package com.kelvin.oocl.crm.filter;

import com.kelvin.oocl.crm.constant.SystemConstant;
import com.kelvin.oocl.crm.entity.Command;

public class SystemFilter {
	private static SystemFilter filter;
	
	public static SystemFilter getInstance(){
		if(filter==null){
			synchronized (SystemFilter.class) {
				if(null==filter){
					filter = new SystemFilter();
				}
			}
		}
		return filter;
	}
	
	private SystemFilter(){}
	
	public Command commandFilter(String input){
		input = input.trim();
		int sta = input.indexOf(" ");
		String s = new String(input);
		if(sta != -1){
			s = input.substring(0, sta);
		}
		Command command = new Command();
		command.setCommond(s);
		if(!SystemConstant.SYSTEM_COMMANDS.contains(s)){
			command.setParameters(null);
			return command;
		}
		if(sta != -1){
			String[] last = input.substring(sta+1, input.length()).split("\\s+");
			command.setParameters(last);
		}else {
			command.setParameters(new String[]{"noparameter"});
		}
		return command;
	}
}
